﻿#pragma once

#include <string>
#include <vector>
#include <map>

#include "libdaq/device/base_device_config.h"

namespace libdaq {
namespace device {
struct BaseDeviceOption {
  std::string name_ = "BaseDevice"; ///< 底层设备类型
  std::string type_ = "BaseType"; ///< 设备类型
  std::string hardware_version_ = "0.0.0"; ///< 底层硬件版本
  std::string boot_loader_version_ = "0.0.0"; ///< 底层BootLoader版本
  std::string software_version_ = "0.0.0"; ///< 底层软件版本
  std::string sn_version_ = "0000000000000000"; ///< 设备SN码
  std::string mcu_uid_version_ = " "; ///< MCU UID
  std::string device_address_ = "0"; ///< 设备地址
  std::string mac_address_ = "00:00:00:00:00:00"; ///< Mac地址
  std::string ip_address_ = "0.0.0.0"; ///< IP地址
  std::string net_mask_ = "0.0.0.0"; ///< 子网掩码
  std::string gateway_ = "0.0.0.0"; ///< 网关
  std::string server_port_ = "0"; ///< 服务端口
  std::string rtc_time_ = "0"; ///< RTC时间
};

struct BasePacketOption {
  unsigned char device_address_ = 0x01; ///< 设备默认地址
  uint32_t send_packet_header_ = 0x55AA524C; ///< 发送数据包包头
  uint32_t send_packet_tail_ = 0xA55ACCBB; ///< 发送数据包包尾
  std::vector<unsigned char> raw_data_header_ = {0x5A, 0x4A, 0x55, 0xAA}; ///< 返回包包头
  std::vector<unsigned char> raw_data_tail_ = {0xDD, 0xEE, 0xA5, 0x5A,}; ///< 返回包包尾
  int raw_data_size_ = 1004; ///< 返回包数据长度大小
};

struct BaseADCOption {
  uint8_t legal_channel_size_ = 0; ///< 合法的设备ADC通道数
  std::vector<LockzhinerADCChannel> legal_channel_ = {LockzhinerADCChannel::ADCChannelAINNone}; ///< 合法的电压通道
  std::vector<LockzhinerADCSampleRate> legal_sample_rate_ = {LockzhinerADCSampleRate::ADCSampleRate_None}; ///< 合法的采样率
  std::vector<LockzhinerADCVoltage> legal_voltage_ = {LockzhinerADCVoltage::ADCVoltage_None}; ///< 合法的电压量程
  uint32_t legal_trigger_timeout_max_ = 0; ///< 触发接收数据最大超时时间
  uint32_t legal_trigger_timeout_min_ = 0; ///< 触发接收数据最小超时时间
  uint32_t legal_trigger_length_max_ = 0; ///< 触发接收数据最大长度
  uint32_t legal_trigger_length_min_ = 0; ///< 触发接收数据最小长度

  uint8_t current_channel_state_ = 0b11111111; ///< ADC通道状态，每一位代表一个通道
  LockzhinerADCTriggerType current_trigger_type_ = LockzhinerADCTriggerType::Normal; ///< 当前触发模式
  LockzhinerADCTriggerMode current_trigger_mode_ = LockzhinerADCTriggerMode::Automatic;  ///< 当前触发方式
  uint32_t current_trigger_data_length_ = 0; ///< 当前触发数据长度
  LockzhinerADCSampleRate current_sample_rate_ = LockzhinerADCSampleRate::ADCSampleRate_None; ///< 当前采样率
  std::vector<LockzhinerADCVoltage> current_voltage_ = {};  // 当前各通道电压量程
  // std::map<LockzhinerADCVoltage, int> voltage_map_; ///< 电压量程与协议值的映射

  std::vector<uint16_t> offset_calibration_x1_state = {}; // 各通道偏置校准X1参数
  std::vector<uint16_t> offset_calibration_2_5_state = {}; // 各通道偏置校准2.5V参数
  std::vector<uint16_t> offset_calibration_5_state = {}; // 各通道偏置校准5V参数
  std::vector<uint16_t> offset_calibration_x10_state = {}; // 各通道偏置校准X10参数
  std::vector<uint16_t> gain_calibration_x1_state = {}; // 各通道增益校准X1参数
  std::vector<uint16_t> gain_calibration_x10_state = {}; // 各通道增益校准X10参数

  uint32_t channel_data_buffer_size_ = 10 * 1024 * 1024; ///< 通道数据大小
};

struct BaseSystemOpOption {
    std::vector<uint8_t> ip_address_ = {};    // 板卡IP地址
    uint16_t port_ = 0;                       // 板卡端口号
    uint8_t device_address_ = 0;              // 设备地址
    std::string device_name_;                 // 设备名称
    std::vector<uint8_t> mac_address_ = {};   // 板卡MAC地址
    std::vector<uint8_t> netmask_ = {};       // 板卡子网掩码
    std::vector<uint8_t> broadcast_ = {};     // 板卡网关

    std::vector<uint8_t> server_ip_address_ = {};   // 服务器IP地址
    uint16_t server_port_ = 0;                      // 服务器端口号
};

struct BaseProductTestOption {
    std::vector<uint8_t> default_config;    // 默认配置
    std::vector<uint8_t> sn;                // 产品SN
    std::vector<uint8_t> eeprom_uid;        // eeprom的UID号
};
} // namespace device
} // namespace libdaq
